package work20241121;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author zdl
 * @date 2024/11/21
 */
public class Demo3 {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        String[] fruit = {"苹果","香蕉","橙子"};
        boolean isRunning = true;
        int num = 0;
        while (isRunning){
           switch (2){
               case 1:
                   System.out.println("请输入添加水果名称:");
                   String fruitName = sc.next();
                   int count = 0;
                   count++;
                   String[] fruit1 = new String[fruit.length+count];
                   for (int i = 0; i < fruit.length; i++) {
                       fruit1[i] = fruit[i];
                   }
                   fruit1[fruit1.length+count] = fruitName;
                   System.out.println(Arrays.toString(fruit1));
                   break;
               case 2:
                   System.out.println("删除水果");
                   System.out.println("请选择删除水果名称:");
                   String str = sc.next();
                   for (int i = 0; i < fruit.length; i++) {
                       if(str.equals(fruit[i])){
                           String[] delFruit = new String[fruit.length - 1];
                           int delIndex = i;
                           for (int j = delIndex; j <fruit.length-1 ; j++) {
                               fruit[j] = fruit[j+1];
                           }
                           for (int j = 0; j < fruit.length-1; j++) {
                               delFruit[j] = fruit[j];
                           }
                           System.out.println(Arrays.toString(delFruit));
                       }

                   }
                   break;

               case 3:
                   System.out.println("请选择修改水果信息:");
                   System.out.println("请选择删除水果名称:");
                   String updateName = sc.next();
                   for (int i = 0; i < fruit.length; i++) {
                       if(updateName.equals(fruit[i])){
                           fruit[i] = updateName;
                       }
                   }
           }


        }

    }
}
